#message-box {
  --gap: 3rem;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  position: fixed;
  background-color: rgba(0, 0, 0, 0.45);
  animation: fadein .25s ease-in-out;
  z-index: 9999990;
  pointer-events: auto;
  -moz-user-select: none;

  #stylus-popup & {
    align-items: center;
    justify-content: center;
    animation: none;
  }

  > div {
    top: var(--gap);
    right: var(--gap);
    min-width: 10rem;
    max-width: 50vw;
    min-height: 5rem;
    max-height: calc(var(--100dvh) - 2*var(--gap));
    position: fixed;
    display: flex;
    flex-direction: column;
    background-color: var(--bg);
    box-shadow: 5px 5px 50px rgba(0, 0, 0, 0.225);
    z-index: 9999991;
    -moz-user-select: text;
    @media screen and (max-width: 850px), compact {
      --gap: 1rem;
      max-width: calc(100% - 2*var(--gap));
    }
    @media (max-height: 600px) {
      --gap: 1rem;
    }
  }

  &.fadeout {
    animation: fadeout .25s ease-in-out;
  }

  &:is(.center, .center-dialog) {
    align-items: center;
    justify-content: center;
    > div {
      top: unset;
      right: unset;
    }
  }

  &.center #message-box-contents {
    text-align: center;
    & pre {
      text-align: left;
    }
  }

  &.pre #message-box-contents {
    white-space: pre-line;
    font-family: monospace;
    text-align: left;
  }

  &.pre-line #message-box-contents {
    white-space: pre-line;
  }
}


#message-box-title:not(:empty) {
  font-weight: bold;
  background-color: var(--accent-3);
  padding: .75rem 2.5rem .75rem 52px;
  font-size: 1rem;
  position: relative;
  min-height: 42px;
  box-sizing: border-box;
  cursor: move;
  user-select: none;
  -moz-user-select: none;
  &::before {
    content: "";
    width: 0;
    height: 0;
    padding: 0 32px 32px 0;
    background: url(../../icon/32.png);
    position: absolute;
    left: .5rem;
    top: 0;
    bottom: 0;
    margin: auto;
  }
}
#message-box-title:empty,
#message-box-title:empty + #message-box-close-icon {
  display: none;
}

#message-box.danger {
  #message-box-title {
    background-color: firebrick;
    color: white;
  }
  #message-box-title::before {
    background: url(../../icon/32x.png);
  }
  #message-box-contents {
    font-weight: bold;
  }
  #message-box-close-icon i {
    color: maroon;
    &:hover {
      color: #600;
    }
  }
}

#message-box.note {
  align-items: center;
  justify-content: center;
  white-space: pre-wrap;
  > div {
    max-width: 40em;
    top: unset;
    right: unset;
    position: relative;
  }
}

#message-box-close-icon {
  cursor: pointer;
  position: absolute;
  right: 0;
  top: 0;
  & i {
    font-size: 16px;
    padding: .75rem;
    display: block;
  }
}

#message-box-contents {
  overflow: auto;
  padding: 1rem;
  position: relative;
  flex-grow: 9;
  overflow-wrap: break-word;
  & p {
    &:first-child {
      margin-top: 0;
    }
    &:last-child {
      margin-bottom: 0;
    }
  }
}

#message-box-buttons {
  padding: .75rem .375rem;
  background-color: var(--c95);
  text-align: center;
  .danger & > button:not([data-focused-via-click]):first-child:focus {
    box-shadow: 0 0 0 1px red; /* Using box-shadow instead of the ugly outline in new Chrome */
  }
  .non-windows & {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row-reverse;
  }
  .non-windows & > :nth-child(1),
  > :nth-child(n + 2) {
    margin-left: .5rem;
  }
}
